package com.prashantdctm.utils;



import java.io.FileOutputStream;
import java.io.PrintStream;

public class LogFile {
	private  FileOutputStream logFile;
	private  PrintStream ps;
	
	public static void main (String args[]) {
		
	}
	
	public LogFile(String filePath, boolean append) {
		try {
			logFile = new FileOutputStream(filePath, append);
			ps = new PrintStream(logFile);
		} catch (Exception e){
			e.printStackTrace();
		}
		
	}
	
	public synchronized void closeLog() {
		try {
			ps.close();
			logFile.close();
		} catch (Exception e){
			e.printStackTrace();
		}
	}
	
	/** Logs the message as well as prints them on screen if printToConsole is true */
	public synchronized void log(String msg, boolean printToConsole) {
		log(msg);
		if(printToConsole) {
			System.out.println(msg);
		}
	}
	
	public void log(String msg) {
		ps.println(msg);
		System.out.println(msg);
	}

	
}

